package com.jr.mapper;

import com.jr.pojo.CareProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface CareProviderMapper {

    @Select("SELECT * FROM care_providers WHERE provider_id = #{providerId}")
    CareProvider selectById(Integer providerId);

    @Select("SELECT * FROM care_providers WHERE user_id = #{userId}")
    CareProvider selectByUserId(Integer userId);

    @Insert("INSERT INTO care_providers (user_id, business_name, business_license, contact_person, business_address, " +
            "service_area, capacity, rating, review_count, status, created_at, updated_at) " +
            "VALUES (#{userId}, #{businessName}, #{businessLicense}, #{contactPerson}, #{businessAddress}, " +
            "#{serviceArea}, #{capacity}, #{rating}, #{reviewCount}, #{status}, #{createdAt}, #{updatedAt})")
    @Options(useGeneratedKeys = true, keyProperty = "providerId")
    int insertCareProvider(CareProvider careProvider);

    @Update("UPDATE care_providers SET business_name=#{businessName}, business_license=#{businessLicense}, " +
            "contact_person=#{contactPerson}, business_address=#{businessAddress}, service_area=#{serviceArea}, " +
            "capacity=#{capacity}, rating=#{rating}, review_count=#{reviewCount}, status=#{status}, updated_at=#{updatedAt} " +
            "WHERE provider_id=#{providerId}")
    int updateCareProvider(CareProvider careProvider);

    @Select("SELECT * FROM care_providers WHERE status = #{status}")
    List<CareProvider> selectByStatus(String status);

    @Select("SELECT * FROM care_providers WHERE service_area LIKE CONCAT('%', #{area}, '%')")
    List<CareProvider> selectByServiceArea(String area);

    @Select("SELECT * FROM care_providers ORDER BY rating DESC LIMIT #{limit}")
    List<CareProvider> selectTopRated(Integer limit);

    @Select("SELECT * FROM care_providers WHERE status = 'approved' ORDER BY rating DESC")
    List<CareProvider> selectAllApproved();
}
